const {getHttpCat} = require("../../models/http.js")
const {numpro} = require("../../utils/music.js")

Page({
  data:{
    playlists:"" 
  },

  onLoad: function (options) {
    this.getHttpData();
  },
  onReachBottom: function () {
    this.getHttpData()
  },
  
  getHttpData() {
    getHttpCat({
      offset: this.data.playlists.length,
      success: res => {
         let playlists = [...this.data.playlists, ...res.data.playlists]
          playlists.forEach(item=>{
            item.playCount = numpro(item.playCount)
           })
          this.setData({
            playlists
          })
      }
    })
  },

  handleToggle(event){
    let {id} = event.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/music-detail/music-detail?id=${id}`,
    });
  }
})
